******Master teacher monitoring do file****
******Purpose: To run all the cleaning do files for the teacher monitoring survey
******and save a clean data set
******Last modified: 4th April 2019****

clear all
cap log close

do "[directory]/02 Teacher_Monitoring_Cleaning.do"

do "[directory]/03 Teacher_Monitoring_Correction.do"

\
save "[directory]/teacher_monitoring_endline_preclean.dta", replace

do "[directory]/04 Teacher_Monitoring_Correction_final.do"

save "[directory]/teacher_monitoring_endline_clean_final.dta", replace


	local piivars sector_102 cell_103 village_104
	local piinum -99999
	local piistr NONPII VERSION
	generate piiid = _n
	ds `piivars', has(type numeric)
	foreach var in `r(varlist)' {
		replace `var' = `piinum' if !missing(`var')
	}
	ds `piivars', has(type string)
	foreach var in `r(varlist)' {
		replace `var' = "`piistr'" if !inlist(`var', "", "don't know", "refusal")
	}

save "[directory]/teacher_monitoring_endline_clean_final_NOPIIs.dta", replace
